package com.guigu.oss.controller;

import com.atguigu.commonutils.R;
import com.guigu.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author 王佳晨
 */
@Api(description="阿里云文件管理")
@RestController
@RequestMapping("/eduoss/fileoss")
@CrossOrigin
public class OssController {
    @Resource
    private OssService ossService;

    //上传头像的方法
    @PostMapping
    public R uploadOssFile(@ApiParam(name = "file", value = "文件", required = true)
                               @RequestParam("file") MultipartFile file) {
        //获取上传文件 MultipartFile
        //返回上传到oss的路径
        String url = ossService.uploadFileAvatar(file);

        //返回r对象
        return R.ok().message("文件上传成功").data("url", url);

    }

}
